﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp.Study.Test
{
    public class 字符串操作
    {
        public static void Go()
        {
            SplitByChars();
            SplitByStrings();
        }

        /// <summary>
        /// 通过多个char字符分隔
        /// </summary>
        private static void SplitByChars()
        {
            string str = "111,22.33=444|55?666!777。8888，9999 10";
            char[] chars = { ',', '.', '，', '。', '|', '!', '=', '?', ' ' };
            var list = str.Split(chars).ToList();
            Console.WriteLine("SplitByChars：");
            ListConsole(list);
        }

        /// <summary>
        /// 通过多个string字符串分隔
        /// </summary>
        private static void SplitByStrings()
        {
            string str = "111分隔符22分隔符33分割444分隔55隔开666";
            string[] strings = { "分隔符","分隔","分割","隔开" };
            var list = str.Split(strings,System.StringSplitOptions.RemoveEmptyEntries).ToList();
            Console.WriteLine("SplitByStrings：");
            ListConsole(list);
        }

        private static void ListConsole(IList<string> list)
        {
            foreach (string str in list)
            {
                Console.Write($"  {str}  ");
            }
            Console.WriteLine();
        }
    }
}
